public class GetHint {

    public static void main(String[] args) {
        GetHint getHint = new GetHint();
        String secret = "1807", guess = "7810";
        System.out.println(getHint.getHint(secret, guess));
    }

    public String getHint(String secret, String guess) {
        char[] c1 = secret.toCharArray();
        char[] c2 = guess.toCharArray();
        int[] arrG = new int[10];
        int[] arrS = new int[10];
        int bulls = 0;
        int cows = 0;
        for (int i = 0; i < c1.length; i++) {
            if (c1[i] == c2[i]) {
                ++bulls;
            } else {
                ++arrG[c2[i] - '0'];
                ++arrS[c1[i] - '0'];
            }
        }
        for (int i = 0; i < 10; i++) {
            cows += Math.min(arrG[i], arrS[i]);
        }
        return bulls + "A" + cows + "B";
    }
}
